package com.wwj.auction.admin.controller;


import com.wwj.auction.admin.entity.vo.PageModel;
import com.wwj.auction.admin.entity.vo.StoreTempVo;
import com.wwj.auction.admin.entity.vo.StoreVo;
import com.wwj.auction.admin.service.StoreService;
import com.wwj.auction.common.result.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collections;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author wwj
 * @since 2021-08-25
 */
@RestController
@RequestMapping("/admin/store")
public class StoreController {

    @Autowired
    private StoreService storeService;

    /**
     * 根据用户id查询店铺信息
     *
     * @param id
     * @return
     */
    @GetMapping("/getStoreInfo/{id}")
    public R getStoreInfo(@PathVariable("id") Integer id) {
        StoreVo storeVo = storeService.getStoreInfo(id);
        return R.ok().data("storeInfo", Collections.singletonList(storeVo));
    }

    /**
     * 分页查询所有店铺信息
     *
     * @return
     */
    @GetMapping("/list/{page}/{limit}")
    public R list(
            @PathVariable("page") Integer page,
            @PathVariable("limit") Integer limit) {
        PageModel<StoreTempVo> pageModel = storeService.listForStore(page, limit);
        return R.ok().data("pageModel", pageModel);
    }

    /**
     * 通过店铺id更改店铺状态
     *
     * @param storeId
     * @param status
     * @return
     */
    @GetMapping("/status/{storeId}/{status}")
    public R status(
            @PathVariable("storeId") Integer storeId,
            @PathVariable("status") Integer status) {
        storeService.status(storeId, status);
        return R.ok().message("操作成功");
    }
}

